package com.bit.bit_forum.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class AppInterceptorConfigure implements WebMvcConfigurer {
    // 注入自定义的登录拦截器
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加登录拦截器
        registry.addInterceptor(loginInterceptor)
//                .excludePathPatterns("/**");
                .addPathPatterns("/**")
                .excludePathPatterns("/sign-in.html")
                .excludePathPatterns("/sign-up.html")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/register")
                .excludePathPatterns("/user/logout")
                .excludePathPatterns("/swagger*/**")
                .excludePathPatterns("/v3*/**")
                .excludePathPatterns("/dist/**") //排除所有静态文件
                .excludePathPatterns("/image/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/**.ico");
        WebMvcConfigurer.super.addInterceptors(registry);
    }


}
